<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.5.1.min.js"></script>
</head>
<body>
    <H1>多选框，全部选中或者全部取消</H1>
<div>
    爱好:
    <input type="checkbox" name="hobby" id="hobby" />乒乓球
    <input type="checkbox" name="hobby" id="hobby" />象棋
    <input type="checkbox" name="hobby" id="hobby" />荡秋千
</div>
<div>
    <button id="selectAll">全选</buuton>
    <button id="unSelectAll">全取消</button>
</div>    
</body>
<script>
 //jQuery checked属性,true选中，false不选
 $("#selectAll").click(function(){
 //attr方法只能执行一次，jQeury1.6如果是boolean使用prop
$("[id=hobby]").attr("checked",true);
})

$("#unSelectAll").click(function(){
    $("[id=hobby]").attr("checked",false);
})
</script>
</html>